﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.IO.Ports;




namespace UartConnect
{
    public partial class Form1 : Form
    {


        SerialPort Sp;



        public Form1()
        {
            InitializeComponent();
            Sp = new SerialPort();

            SpNameTextBox.Text = "COM6";



        }

        private void SendButton_Click(object sender, EventArgs e)
        {

        }

        private void SpOpenButton_Click(object sender, EventArgs e)
        {
            Sp.PortName = SpNameTextBox.Text;
            Sp.BaudRate = 9600;
            Sp.DataBits = 8;
            Sp.Parity = Parity.None;
            Sp.StopBits = StopBits.One;
            Sp.DataReceived += Sp_DataReceived;
            Sp.Open();



          

           
        }

        void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            RecvTextBox.Text = "";
            byte[] nBuff = new byte[100];
            Sp.Read(nBuff, 0, 100);
            RecvTextBox.Text += System.Text.ASCIIEncoding.ASCII.GetString(nBuff) ;
            RecvTextBox.Text += "\r\n";
        }



      



        private void SpCloseButton_Click(object sender, EventArgs e)
        {
            Sp.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Sp.Write("1"); 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Sp.Write("2");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Sp.Write("3");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Sp.Write("+");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Sp.Write("4");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Sp.Write("5");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Sp.Write("6");
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Sp.Write("-");
        }

        private void button9_Click(object sender, EventArgs e)
        {
            Sp.Write("7");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Sp.Write("8");
        }

        private void button11_Click(object sender, EventArgs e)
        {
            Sp.Write("9");
        }

        private void button12_Click(object sender, EventArgs e)
        {
            Sp.Write("*");
        }

        private void button13_Click(object sender, EventArgs e)
        {
            Sp.Write("0");
        }

        private void button14_Click(object sender, EventArgs e)
        {
            Sp.Write(".");
        }

        private void button15_Click(object sender, EventArgs e)
        {
            Sp.Write("=");
        }

        private void button16_Click(object sender, EventArgs e)
        {
            Sp.Write("/");
        }

        private void ClearZero_button_Click(object sender, EventArgs e)
        {
            Sp.Write("z");
            
        }

        private void Bt_Button_Click(object sender, EventArgs e)
        {



            Sp.Write("AT\r\n");








        }

    
    
    }

}
